package roborally.program.conditions;

import java.util.Iterator;

import roborally.model.Element;
import roborally.model.Orientation;
import roborally.model.Position;
import roborally.model.Robot;

/**
 * A class for dealing with true-conditions: (wall).  
 * 
 * @version	1.0
 * @author  Pieter Robberechts	(1e Bach Informatica)
 * @author	Jeroen Sanders		(1e Bach Informatica)
 *
 */
public class Wall extends Condition {

	/**
	 * Initialize this new wall-condition with a line-number.
	 * 
	 */
	public Wall(int lineNb) {
		super(lineNb);
	}

	/**
	 * Evaluate this condition for a given robot.
	 * 
	 * @return	Return true if and only if there is a wall to the right of the robot;
	 * 			else return false.
	 * 			| for one element in robot.getBoard().getElements(robot.getPosition().getNeighbour(Orientation.RIGHT)) :
	 * 			| 	result == (element instanceof roborally.model.wall)
	 */
	@Override
	public boolean evaluate(Robot robot) {
		if(!super.evaluate(robot))
			return false;
		
		Position positionRightOfRobot = robot.getPosition().getNeighbour(Orientation.RIGHT);
		Iterator<Element> elementsRightOfRobot = robot.getBoard().getElements(positionRightOfRobot).iterator();

		return elementsRightOfRobot.hasNext() && 
				elementsRightOfRobot.next() instanceof roborally.model.Wall;
	}
	
	/**
	 * Return a textual representation of this wall-condition,
	 * formatted in accordance with its position in the program.
	 * 
	 * @return	The result is a pretty formatted string of this wall-condition,
	 * 			taking in account his relative position in the program.
	 * 			| result == getIndentation(indentationLevel) + "(wall)"
	 */
	@Override
	public String prettyFormat(int indentationLevel) {
		return getIndentation(indentationLevel) + "(wall)";
	}

}
